package de.hs.rm.jmx;

import java.lang.management.ManagementFactory;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;

public class Agent {
	
	public static void main(String[] args) throws Exception { 
	     
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 

//###########################HelloWordMBean############################
        ObjectName name = new ObjectName("de.hs.rm.jmx:type=HelloWorld"); 
        HelloWorld mbean = new HelloWorld(); 
        mbs.registerMBean(mbean, name);
        
//###########################QueueSamplerMBean############################        
        ObjectName mxbeanName = new ObjectName("de.hs.rm.jmx:type=QueueSampler");
        Queue<String> queue = new ArrayBlockingQueue<String>(10);
        queue.add("Request-1");
        queue.add("Request-2");
        queue.add("Request-3");
        QueueSampler mxbean = new QueueSampler(queue);
        mbs.registerMBean(mxbean, mxbeanName);
        
//###########################SimpleOpenMBean################################
        ObjectName openMBeanObjectName = new ObjectName("de.hs.rm.jmx:type=SimpleOpenMBean");
        SimpleOpenMBean openMBean = new SimpleOpenMBean();
		CompositeData tShirt1 = openMBean.buildTShirt(null, null, null, new Float(10.0f));
		CompositeData tShirt2 = openMBean.buildTShirt("JDMK", "red", "L", new Float(15.0f));
		openMBean.addTShirt(tShirt1);
		openMBean.addTShirt(tShirt2);
		mbs.registerMBean(openMBean, openMBeanObjectName);
		
//###########################PageSizeResultOpenMBean################################
		ObjectName psrObjName = new ObjectName("de.hs.rm.jmx:type=PageSizeResult");
		PageSizeResultOpenMBean psrMBean = new PageSizeResultOpenMBean();
		mbs.registerMBean(psrMBean, psrObjName);
		
//###########################PizzeriaMXBean################################
		ObjectName pizzeriaObjName = new ObjectName("de.hs.rm.jmx:type=Pizzeria");
		Pizzeria pizzeriaMBean = new Pizzeria();
		Pizza pizza1 = new Pizza("Salami", 6.90, true);
		Pizza pizza2 = new Pizza("Funghi", 9.50, true);
		Pizza pizza3 = new Pizza("Hawaii", 7.90, false);
		pizzeriaMBean.addPizzaToMenu(pizza1);
		pizzeriaMBean.addPizzaToMenu(pizza2);
		pizzeriaMBean.addPizzaToMenu(pizza3);		
		mbs.registerMBean(pizzeriaMBean, pizzeriaObjName);

//###########################StartServer##############################     
        System.out.println("Waiting forever..."); 
        Thread.sleep(Long.MAX_VALUE); 
    } 

}
